﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using wlm.wsx;
using System.Xml;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            XmlDocument doc = new XmlDocument();
            try
            {
                if (!string.IsNullOrEmpty(FILEPATH.Text))
                {
                    doc.Load(FILEPATH.Text);
                }
                else if (!string.IsNullOrEmpty(textBox1.Text))
                {
                    doc.LoadXml(textBox1.Text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("xml文件错误，请检查xml文件!");
            }
             //if (string.IsNullOrEmpty (str)) return;
 
            wlm.wsx.src.wlm.Newwsx.Parser p = new wlm.wsx.src.wlm.Newwsx.Parser();
            textBox2.Text = p.Parse(doc);
            //Parser parser = new Parser (new Scanner (str));
            //Operator op = parser .Parse ();
            //if (op != null)
            //textBox2.Text = op.ToXML ();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "XML files (*.xml)|*.xml" ;
            openFileDialog1.RestoreDirectory = true ;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FILEPATH.Text = openFileDialog1.FileName;
            }
        }        
    }
}
